<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./libs/jquery.js"></script>
  </head>
  <body>
    <script>
      const p1 = new Promise((resolve, reject) => {
        $.ajax({
          url: 'http://localhost:3000/personalized',
          success: (res) => {
            resolve(res)
          },
          error: () => {
            reject({ msg: '请求失败' })
          },
        })
      })

      // 写法1. 通过 then 获取 p1 对象成功状态的数据
      p1.then((res) => {
        console.log(res)
      })

      // await 的父级函数需要写 async 关键词才行
      ;(async () => {
        // 写法2. await 语法糖改造 then 写法。
        const res = await p1
        console.log(res)
      })()
    </script>
  </body>
</html>
